<html>
<head><meta charset="utf-8"><title>format! can address named arguments by position · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html">format! can address named arguments by position</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="187998442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/187998442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#187998442">(Feb 12 2020 at 10:42)</a>:</h4>
<p>While implementing asm! I noticed that it is possible for format strings to address named argument by position: <code>println!("{0} {foo}", foo = 2);</code> prints <code>2 2</code>.</p>



<a name="187998502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/187998502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#187998502">(Feb 12 2020 at 10:42)</a>:</h4>
<p>Is this intentional? The <code>fmt</code> documentation doesn't explicitly say that it isn't allowed, but it feels like it should be...</p>



<a name="188000209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/188000209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#188000209">(Feb 12 2020 at 11:09)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="116015">@Alex Crichton</span> <span class="user-mention" data-user-id="119031">@Esteban Küber</span></p>



<a name="188012095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/188012095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#188012095">(Feb 12 2020 at 14:04)</a>:</h4>
<blockquote>
<p>It is not valid to put positional parameters (those without names) after arguments which have names.</p>
</blockquote>
<p>Is the only discussion I see in the docs about this</p>



<a name="188012114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/188012114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#188012114">(Feb 12 2020 at 14:04)</a>:</h4>
<p>My guess is that it's unintentional but also unchangeable at this point</p>



<a name="188012779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/188012779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#188012779">(Feb 12 2020 at 14:12)</a>:</h4>
<p>If it's unintentional then we could add a warning for it (maybe even a deny-by-default lint).</p>



<a name="188012816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/188012816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#188012816">(Feb 12 2020 at 14:13)</a>:</h4>
<p>I'm mainly asking because I'm working on <code>asm!</code> and wondering whether I should emulate this behavior.</p>



<a name="188012948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/188012948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#188012948">(Feb 12 2020 at 14:14)</a>:</h4>
<p>I think we should keep them consistent. I personally think positional arguments were probably a mistake (as a user-facing detail), and we could warn on this I guess, though I don't know that there's much point.</p>



<a name="188026114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/188026114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#188026114">(Feb 12 2020 at 16:23)</a>:</h4>
<p>That behavior feels surprising to me, I suspect it was an accident</p>



<a name="188030501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/188030501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#188030501">(Feb 12 2020 at 17:05)</a>:</h4>
<p>A quick bisects shows that this was actually rejected until 1.12.0, which started accepting it.</p>



<a name="188030648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/188030648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#188030648">(Feb 12 2020 at 17:07)</a>:</h4>
<p>Possibly introduced by <a href="https://github.com/rust-lang/rust/issues/33642" target="_blank" title="https://github.com/rust-lang/rust/issues/33642">#33642</a></p>



<a name="188053497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/188053497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#188053497">(Feb 12 2020 at 21:11)</a>:</h4>
<p>I would file a ticket to lint on this, I would assume that starting to reject these outright would lead to widespread breakage</p>



<a name="188053978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/188053978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#188053978">(Feb 12 2020 at 21:16)</a>:</h4>
<p>I opened <a href="https://github.com/rust-lang/rust/issues/69110" target="_blank" title="https://github.com/rust-lang/rust/issues/69110">#69110</a> for this</p>



<a name="188055878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/format%21%20can%20address%20named%20arguments%20by%20position/near/188055878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/format!.20can.20address.20named.20arguments.20by.20position.html#188055878">(Feb 12 2020 at 21:40)</a>:</h4>
<p>seems pretty reasonable to at least run crater to see if changing it's clearly not possible at this point</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>